package com.caregiver.watch.business.user.helper;

import com.caregiver.watch.business.user.config.properties.BusinessProperties;
import com.caregiver.watch.business.user.enums.CareRelationshipEnum;
import com.caregiver.watch.business.user.model.po.UserCareRecipient;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.Period;
import java.util.Objects;

/**
 * @Description: 被照护人帮助类
 * @Author 疆戟
 * @Date 2025/10/15 22:42
 * @Version 1.0
 */
@AllArgsConstructor
@Component
public class CareRecipientHelper {

    private final BusinessProperties businessProperties;


    /**
     * 获取被照护人头像
     * @return
     */
    public String getRecipientAvatar(String relationship) {
        String recipientAvatar = StringUtils.EMPTY;
        CareRelationshipEnum relationshipEnum;
        if (StringUtils.isNotBlank(relationship)
                && (relationshipEnum = CareRelationshipEnum.parse(relationship)) != null) {
            recipientAvatar = businessProperties.getAvatarPrefix() + relationshipEnum.getAvatar();
        }
        return recipientAvatar;
    }

    /**
     * 根据生日计算年龄
     * @param birthDate 出生日期
     * @return 年龄
     */
    public static int calculateAge(LocalDate birthDate) {
        LocalDate currentDate = LocalDate.now();
        return Period.between(birthDate, currentDate).getYears();
    }

}
